package com.yuzhihao.writejvm.attributes;

import com.yuzhihao.writejvm.clazz.ClassInfo;
import com.yuzhihao.writejvm.read.Parse;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.log4j.Log4j2;

import java.io.DataInputStream;
import java.io.IOException;

/**
 * 属性
 * <a href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.2">ConstantValueAttribute</a>
 *
 * @author yzh
 * @since 2021年12月10日09:54:02
 */
@Data
@Log4j2
@EqualsAndHashCode(callSuper = true)
public class ConstantValueAttribute extends Attributes {

    private int constantvalue_index_u2 = 2;

    private int constantvalue_index;

    public ConstantValueAttribute(String name){
        super();
        super.setAttribute_name(name);
    }

    @Override
    public void parse(DataInputStream dis, ClassInfo ci) {
        try {
            super.attribute_length = Parse.byteToInt(super.attribute_length_u4, dis);
            this.constantvalue_index = Parse.byteToInt(this.constantvalue_index_u2, dis);
        } catch (IOException e) {
            log.error(e);
        }
    }

}
